var dataMap = new HashMap();
var selectImage = "";

function onChooseClick() {

    let col = $("input[ name='splicing_w']").val();
    let row = $("input[ name='splicing_h']").val();
    var divStr = ""
    for (var i = 1; i <= row; i++) {
        divStr += '<div class="zone-list-box">';
        for (var j = 1; j <= col; j++) {
            divStr += '<div class="item" id="' + i + '_' + j + '">' +
                '<img src="/static/images/addimg.png" class="img_view" id="' + 'img' + i + '_' + j + '" onclick="onListClick(\'img' + i + '_' + j + '\')" >' +
                '</div>'
        }
        divStr += '</div>'
    }

    $('#img_list').html(divStr)
    dataMap.clear()
}

function onListClick(imgid) {
    selectImage = imgid;
    layer.open({
        type: 2,
        title: '选择拼接图片',
        maxmin: true,
        shadeClose: true,
        area: ['850px', '520px'],
        content: 'img_list?imgid=' + imgid
    });

}

function getJsonData() {
    var data = {};
    data.total_col = $("input[ name='splicing_w']").val();
    data.total_row = $("input[ name='splicing_h']").val();
    data.data_list = new Array();
    for (var i = 1; i <= data.total_row; i++) {
        for (var j = 1; j <= data.total_col; j++) {
            var dataArray = {};
            dataArray.row = i;
            dataArray.col = j;
            var key = "img" + i + '_' + j;
            dataArray.img_id = dataMap.get(key);
            data.data_list.push(dataArray)
        }
    }
    return data;
}

function submitSplicing() {
    $.ajax({
        url: url_img,
        type: "POST",
        contentType: 'application/json',
        data: JSON.stringify(getJsonData()),
        success: function (res) {
            if (res.state == 0){
                alert("提交成功")
            }else {
                alert("提交失败")
            }
        }
    })
}

function imgReload(imgId, imgUrl, img) {
}


$(document).ready(function () {
    // var imgStr = "";
    // $.ajax({
    //     url: 'http://127.0.0.1:8000/img/img_list',
    //     type: "POST",
    //     data: "",
    //     success:function (res) {
    //         if (res.state == 0){
    //             var data = $.parseJSON(res);
    //             var array = data["data_list"];
    //             console.log(array);
    //
    //             for (var i=0; i<array.length; i++){
    //                 imgStr += '<div class="item2">' +
    //                     '<img class="item2" src="'+"/"+array[i]["path"]+'">' +
    //                     '</div>'
    //             }
    //             $('#img_list').html(imgStr)
    //         }
    //     }
    // });
});
